#ifndef V8_SCRIPT_PLUGIN
#define V8_SCRIPT_PLUGIN

#include <ScriptManager.h>
#include <v8.h>

using namespace Ogre;
using namespace ScriptPlug;

using v8::Arguments;
using v8::Context;
using v8::Handle;
using v8::HandleScope;
using v8::ObjectTemplate;
using v8::Persistent;
using v8::Script;
using v8::TryCatch;
using v8::Value;

const String pluginName = "V8";

const char* ToCString(const v8::String::Utf8Value& value);

Handle<Value> AddLight(const Arguments& args);
Handle<Value> AddEntity(const Arguments& args);

class V8ScriptPlugin : public IScriptPlugin
{
public:
    V8ScriptPlugin();
    ~V8ScriptPlugin();

    SceneManager* sceneManager;
    Camera* camera;
    Viewport* viewport;

    const String& getName() const;

    void install();
    void initialise();
    void shutdown();
    void uninstall();
    
    void Setup(SceneManager* sceneManager, Camera* camera, Viewport* viewport);
    bool Execute(std::string scriptCode);
    String Result();
    String Error();

private:
    Persistent<Context> context;

    String result;
    String error;

    void BuildErrorString(TryCatch& try_catch);

};

#endif // V8_SCRIPT_PLUGIN